<template>
  <div>
    <!-- 面包屑导航区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>数据统计</el-breadcrumb-item>
      <el-breadcrumb-item>数据报表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图区域 -->
    <el-card>
      <!-- 数据可视化展示 区域 -->
      <div id="main">

      </div>
    </el-card>
  </div>
</template>

<script>
import * as echarts from 'echarts';
import _ from 'lodash'

export default {
  data(){
    return{
      option: {
          xAxis: {
              type: 'category',
              data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
          },
          yAxis: {
              type: 'value'
          },
          series: [{
              data: [820, 932, 901, 934, 1290, 1330, 1320],
              type: 'line'
          }]
      },
    }
  },
  // 此时页面上的DOM元素被渲染完成
  async mounted(){
    // 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('main'));

    const { data: res } = await this.$http.get('reports/type/1');
    if(res.meta.status !== 200) return this.$message.error("获取报表失败");
    const result = _.merge(res.data, this.option);
    // 绘制图表
    myChart.setOption(result);
  },
}
</script>

<style lang='less' scoped>
#main{
  width: 800px;
  height: 400px;
}

</style>